package org.etom.connector.service;

/**
 * The exception is thrown when a critical error is occurred in the system.
 * It is used not only for communication errors.
 */
public class ConnectorException extends Exception {

  private static final long serialVersionUID = 7272916146563634944L;
  
  /**
   * The error code indicates an error in
   * the communication.
   */
  public static final int CONNECTION_ERROR  = 0;
  
  /**
   * The error code includes all others errors.
   */
  public static final int OTHER_ERROR       = 1;
  
  /**
   * The error code indicates an fault response
   * from the server.
   */
  public static final int FAULT_RESPONSE    = 2;
  
  /**
   * The error code indicates an illegal argument
   * which is specified to the some of the methods.
   */
  public static final int ILLEGAL_ARGUMENT  = 3;
  
  private int errorCode;
  
  /**
   * Constructs an exception with an error message and
   * error code.
   * 
   * @param message - the error message
   * @param errorCode - the error code
   */
  public ConnectorException(String message, int errorCode) {
    super(message);
    this.errorCode = errorCode;
  }
  
  /**
   * Constructs an exception with an error message
   * and cause. The error code is set automatically to
   * <code>OTHER_ERROR</code>.
   * @param message
   * @param cause
   */
  public ConnectorException(String message, Throwable cause) {
    super(message, cause);
    this.errorCode = OTHER_ERROR;
  }
  
  /**
   * Constructs an exception with an error message, error code
   * and cause.
   * 
   * @param message - the error message
   * @param errorCode - the error code
   * @param cause - the cause
   */
  public ConnectorException(String message, int errorCode, Throwable cause) {
    super(message, cause);
    this.errorCode = errorCode;
  }
  
  /**
   * The method returns the error code of the exception.
   * 
   * @return - the error code
   */
  public int getErrorCode() {
    return errorCode;
  }
  
}
